<%--
  Created by IntelliJ IDEA.
  User: 施明
  Date: 2019/5/21
  Time: 20:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<c:set var="path" value="${pageContext.request.contextPath}"></c:set>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">

    <title>添加活动商品</title>

    <!-- layui的js -->
    <script src="${path}/layuiadmin/layui/layui.js" charset="utf-8"></script>
    <!-- layui使用的样式-->
    <link rel="stylesheet" href="${path}/layuiadmin/layui/css/layui.css" media="all">

    <link rel="stylesheet" href="${path}/layuiadmin/style/admin.css" media="all">

</head>

<body>




        <label   type="width:210px;">商品一级分类</label>
        <div class="layui-input-inline">
            <select  id="oneLevel" name="oneLevel">
                <option value="0">商品一级分类</option>

            </select>
        </div>

        <label  type="width:210px;">商品二级分类</label>
        <div class="layui-input-inline">
            <select name="twolevel" id="twolevel">
                <option value="0">选择二级分类</option>

            </select>
        </div>

        <label   type="width:210px;">商品：</label>
        <div class="layui-input-inline">
            <select name="goodsid" id="goodsid">
                <option value="0">请选择商品</option>

            </select>
        </div>

    <div class="layui-form-item">
        <label class="layui-form-label" type="width:210px;">秒杀价</label>
        <div class="layui-input-inline">
            <input type="number" name="username" lay-verify="required" min="0" id="price"
                   placeholder="请输入价格" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" type="width:210px;">商品数量</label>
        <div class="layui-input-inline">
            <input type="number" name="username" id="num" lay-verify="required" min="1"
                   placeholder="请输入数量" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn"  id="submit">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>


<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>

    $(function () {
        getOneLevel()
    })
    function getOneLevel() {
        $("#oneLevel").empty()
        $.ajax({//一级联动
            url:"${path}/adminflashgoods.action/findonelevel",
            type:"GET",
            success:function (data) {
                   for(var i = 0 ; i < data.length;i++) {

                       $('#oneLevel').append('<option value="'+data[i].onelevelid+'">'+data[i].onelevelname + '</option>');
                   }
            }
        });
    }
    $("#oneLevel").blur(function () {
        $.ajax({//二级联动，
            url:"${path}/adminflashgoods.action/findtwolevel",
            type:"GET",
            data:{
                onlevelid:$(this).val()
            },
            success:function (data) {
                $("#twolevel").empty()
                for(var i = 0 ; i < data.length;i++) {
                    $('#twolevel').append('<option value="'+data[i].twolevelid+'">'+data[i].twolevelname + '</option>');
                }
            }
        });
    })
    $("#twolevel").blur(function () {
        $.ajax({//二级联动，
            url:"${path}/adminflashgoods.action/findgoodsnotactivity",
            type:"GET",
            data:{
                twolevelid:$(this).val(),
                flashorderid:${orderId}
            },
            success:function (data) {
                $("#goodsid").empty()
                for(var i = 0 ; i < data.length;i++) {
                    $('#goodsid').append('<option value="'+data[i].goodsid+'">'+data[i].goodsname+'</option>');
                }
            }
        });
    })

    $("#submit").click(function () {
        $.ajax({//提交订单
            url:"${path}/adminflashgoods.action/addflashgoods",
            type:"GET",
            data:{
                goodsid:$("#goodsid").val(),
                flashorderid:${orderId},
                price:$("#price").val(),
                num:$("#num").val()
            },
            success:function (data) {
                layui.use(['laypage', 'layer'], function () {
                    var laypage = layui.laypage, layer = layui.layer;
                    layer.msg(data[0]);
                })
            }
        });
    })

</script>


</body>

</html>
